Draws this object’s picture narrower on some rows, so it looks like a barrel, an hourglass, a sign tipped away from you or a wobbling jelly. look is one of the DISTORT_ constants, strength (1 to 3) is how much narrower the narrowest row is, and speed is how fast a DISTORT_WAVE travels down the picture (the other looks ignore it). DISTORT_NONE turns it off.
Works differently on Game Boy - The Game Boy narrows a picture by moving its two sprite pieces toward each other on the lines the look names, so the middle of the line is covered instead of squeezed; 16 pixels wide at most, one bent picture at a time.
Works differently on Game Boy Color - The Game Boy Color narrows a picture by moving its two sprite pieces toward each other on the lines the look names, so the middle of the line is covered instead of squeezed; 16 pixels wide at most, one bent picture at a time.
Works differently on Sega Genesis - The Sega Genesis cannot make a row narrower while the game runs, so its build makes the narrowed pictures ahead of time: one copy of the object's picture for every look and strength the game names (the jelly, DISTORT_WAVE, is 16 copies because it moves) and the object shows the copy that fits. The shapes are the Game Boy Advance's exactly; the jelly steps every second row as the Advance's does. The copies cost room in the game (the build says how much) and no more video memory than a plain picture. An object that holds both a warp and a distortion shows the distortion only. It works on the picture the game draws for an object with no Draw event.
On other consoles this differs: see Side by side and How the consoles differ.
sprite_distort(look, strength, speed)| Name | Type |
|---|---|
look | distort_look |
strength | int |
speed | real |
Nothing.
Draws an object's picture narrower on some rows, so it looks like a barrel, an hourglass, a wobbling jelly or a sign that is tipped toward or away from you. No row is ever drawn wider than the picture is. The hourglass and the jelly change only the width of each row, so they keep every row of the picture. The barrel and the two tipped signs also squeeze the picture a little from top to bottom, so it ends a few rows short: the rows at its narrowest end are cut away, and the stronger the strength, the more of them.


A gold plank stands in for the example's object, because a changing width is easiest to see on a wide, plain shape. First the plank straight, then each look at strength 2. Real pictures from a Game Boy Advance ROM.
You give it three things:
look - which shape. One of the DISTORT_ names (the list is just below). DISTORT_NONE turns the distortion off.strength - a whole number from 1 to 3: how much narrower the narrowest row is. A number past that range is held to the nearest end.speed - how many rows a DISTORT_WAVE travels down the picture every frame. 0 holds it still, a negative number sends it up. The other looks are a shape that stands still, and ignore it.It belongs to the object that calls it, so there is no handle to keep: write sprite_distort(DISTORT_BULGE, 2, 0) in the object's own event and it is the object's picture that is drawn like a barrel. The shape belongs to the picture, so it moves with the object.
| Look | What it is | It uses |
|---|---|---|
DISTORT_BULGE | a barrel: full width in the middle, narrower toward the top and the bottom | 2 slots, 1 matrix |
DISTORT_PINCH | an hourglass: full width at the top and the bottom, pinched in at the waist | 1 slot, 1 matrix |
DISTORT_WAVE | a jelly: narrower and wider again all the way down, both edges moving | 1 slot, 1 matrix |
DISTORT_LEAN_BACK | a sign tipped away from you: full width at the bottom, narrower toward the top | 2 slots, 1 matrix |
DISTORT_LEAN_FORWARD | a sign tipped toward you: full width at the top, narrower toward the bottom | 2 slots, 1 matrix |
The shapes are made for pictures up to about 32 pixels tall. A taller picture gets the same shape, held at its strongest 16 rows above and below the middle.
sprite_distort changes the picture an object gets by itself: the sprite you chose for it, drawn at its place. That means an object with no Draw event. An object that draws itself with draw_sprite and its friends is not changed by it. For those, draw_sprite_3d is the call that curves a picture like a barrel.
The look takes the picture over: the object's own turning and scaling do not apply to a picture that is being distorted, because the shape decides how wide every row is. A script or a room's creation code is not an object, so it has no picture of its own to distort. Calling it there stops a development build with a message that says so.
You do not need to call it every frame. Call it once, in the Create event, and the shape keeps going by itself. Calling it again with the same look and strength only changes the speed. Calling it with a different look or strength swaps the shape; going from a look that uses two slots to one that uses one hands the spare slot back at once.
If the object is hidden, or off the screen, its picture is let go of and the distortion with it, and the matrix and the slots are given back until the picture is there again. Hiding something is not a way to turn a distortion off. Use the next section.
sprite_distort(DISTORT_NONE, 0, 0);This gives the slots and the matrix back straight away, and the picture is drawn the way it always was. The last two numbers are ignored, but they have to be there. When the object is destroyed, or its room ends, the distortion ends by itself and everything it held comes back with nothing for you to do.
Always destroy it, do not hide it. There is no way to hide a distortion, on purpose: something hidden would look gone but would still be using up the console's few row-by-row slots, and then the next effect you ask for would not appear and nothing would tell you why.
A distortion uses one of the console's 32 sprite matrices (the same ones a turned or scaled sprite uses) and one or two of its 8 row-by-row effects, as the table above says, for as long as the object has a picture on the screen. A room change keeps two of the eight for itself, so there are six left for you, shared with everything else that works row by row: sprite_warp, draw_sprite_ripple, draw_text_3d, background_look and a sky from screen_backdrop. You can see how many are in use on the debug screen: the line called H-BLANK.
The shapes live in the cartridge, not in memory: a few thousand bytes for the look you use, in three sizes (for pictures up to 8 rows tall, up to 16, and taller than that). Picking the look with a variable keeps the shapes of all five looks. It costs the console's time too, though not much: measured on a real ROM, about 1 hundredth of a frame for a shape and 1.4 hundredths for a moving jelly.
Ask for more than there is and the game does not skip it. A development build stops with a message that says whether it ran out of slots or of matrices, how many there are, and names every look that is holding one, so you know which one to turn off. A release build, which has no way to stop and show a message, shows the picture straight. It never half-works.
sprite_distort(DISTORT_BULGE, 2, 0);A picture curved like a barrel. Call it in the object's Create event.
if (btn_pressed(BTN_A)) {
sprite_distort(DISTORT_PINCH, 3, 0);
}
if (btn_pressed(BTN_B)) {
sprite_distort(DISTORT_NONE, 0, 0);
}Pressing A pinches the picture in at the waist. Pressing B draws it straight again.
Costs ONE of the console’s 32 sprite matrices (the same ones a turned or scaled sprite uses) and one or two of its 8 row-by-row (H-Blank) effects: a barrel and the two tipped signs take two, an hourglass and a wave take one. A room change keeps two of the eight for itself, so six are left for you, shared with everything else that works row by row. The matrix and the slots are held only while the object has a picture on the screen. The tables are in the cartridge: a few thousand bytes for the look you use, in three sizes: for pictures up to 8 rows tall, up to 16, and taller than that. It works on the picture the engine draws for the object by itself, which means an object with no Draw event (draw_sprite_3d is the call for a picture you draw yourself). No row is ever drawn wider than the picture is, because a wider row would be cut off by the sprite’s own box. The barrel and the two tipped signs also squeeze the picture a little from top to bottom, so it ends a few rows short (the rows at its narrowest end are cut away). A distorted sprite is not turned or scaled by its object: the look decides how wide each row is. Call it from the object’s own event, once. The look belongs to the object: when it is destroyed, or its room ends, the look ends and everything it holds comes back. Turning it off with DISTORT_NONE hands them back at once, but hiding something does not: destroy it, do not hide it. If there is no room for another one - or no matrix - a development build stops with a message that says which and names every look holding a slot; a release build shows the sprite straight.